<?php
/**
 * Created by PhpStorm.
 * User: sofwu
 * Date: 2019/1/11
 * Time: 下午3:13
 */
namespace App\Http\Controllers\Api\V1;


use App\Http\Transformer\KeywordsTransformer;
use App\Model\Keywords;

class KeywordsController extends Controller
{
    /**
     * 获取心愿随机显示
     */
    public function keysList()
    {
        $keys = Keywords::where(['enabled'=>1])->inRandomOrder()->limit(9)->get();
        return $this->response->collection($keys, new KeywordsTransformer);
    }


    /**
     * 上传心愿
     */
    public function store()
    {
        $payload = app('request')->only('key');
        $keys = new Keywords;
        $keys->name = $payload['key'];
        $keys->save();
        return $this->response->array($keys);
    }
}